'use strict';
app.controller('modulesShopsCtrl', ['$stateParams','$rootScope','$state',function ($stateParams,$rootScope) {
    $rootScope.modulesId=$stateParams.modulesId;
    $rootScope.statusObject = [
        {name: '营业中', value: '0'},
        {name: '休息中', value: '1'},
        {name: '停止经营', value: '2'},
    ];
    $rootScope.modulesShopsVO = {
        modulesId: $stateParams.modulesId
    };
}])

app.controller('modulesCtrl',['$scope','$rootScope','utilService','modulesShopsService','toaster','$state',function($scope,$rootScope,utilService,modulesShopsService,toaster,$state){
    //查询模块店铺列表
    $scope.findModulesShopAll = function () {
        utilService.queryForPagingList($scope, {
            url: $scope.app.domain + 'modules/shops',
            params: $scope.modulesShopsVO
        }).then(function (result) {
        });
    }
    $scope.findModulesShopAll();
    //移除模块店铺
    $scope.delModulesShop= function (modulesShop) {
        $scope.modulesShopsVO.csId=modulesShop.id;
        modulesShopsService.delModulesShop($scope).then(function(result){
            switch (result.status){
                case 200:
                    toaster.pop('success', "提示", "操作成功");
                    $state.reload();
                    break;
                case 655:
                    toaster.pop('waiting', "操作失败", result.message);
                    break;
                default :
                    toaster.pop('error', "操作失败", "发生未知错误！请联系管理员");
                    break;
            }
        })
    }

}])
app.controller('shopsCtrl',['$scope','$cookies','$rootScope','utilService','modulesShopsService','toaster','$state',function($scope,$cookies,$rootScope,utilService,modulesShopsService,toaster,$state){
    $scope.shopsVO = {
        sessionId: $cookies.sessionId,
        modulesId:$scope.modulesId
    };
    //查询店铺列表
    $scope.findShopAll = function () {
        utilService.queryForPagingList($scope, {
            url: $scope.app.domain + 'shop/get/list/formodules',
            params: $scope.shopsVO
        }).then(function (result) {
        });
    }
    $scope.findShopAll();
    //添加商品
    $scope.addModulesShop= function (shop) {
        $scope.modulesShopsVO.csId=shop.id;
        $scope.modulesShopsVO.status=shop.status;
        modulesShopsService.addModulesShop($scope).then(function(result){
            switch (result.status){
                case 200:
                    toaster.pop('success', "提示", "操作成功");
                    $state.reload();
                    break;
                case 658:
                    toaster.pop('waiting', "操作失败", result.message);
                    break;
                default :
                    toaster.pop('error', "操作失败", "发生未知错误！请联系管理员");
                    break;
            }
        })
    }
}])